Support for try-with-resources by reduction #3918
Open
wadoon wants to merge 7 commits into
Open
Conversation
unp1
requested changes
Jul 12, 2026
unp1
left a comment
Member
There was a problem hiding this comment.
Only small things:
-
Throwable.addSuppressed(...) is not in KeY's Throwable stub, the desugaring emits primaryExc.addSuppressed(...).
-
java.lang.AutoCloseable is absent from ReduX (only java.io.Closeable exists), so a resource that implements AutoCloseable directly won't resolve.
-try (this.r) (field-access resource) fails in KeY: "Cannot resolve 'this.r'", because the transform stringified the field access into a single NameExpr
Thanks!
f636b77 to
861a8c3
Compare
unp1
requested changes
Jul 13, 2026
unp1
approved these changes
Jul 13, 2026
c101944 to
da61fda
Compare
Member
Author
|
#3919 is ahead and will destroy the mergeability. |
# Conflicts: # key.core/src/main/java/de/uka/ilkd/key/java/transformations/KeYJavaPipeline.java
Added some specifications to addSuppressed so that it is closed automatically
da61fda to
e50c794
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pull Request Description
Related Issue
This pull request resolves # [add issue number if applicable]
Intended Change
This PR implements the complete desugaring transformation for try-with-resources statements in the KeY Java transformation pipeline. The
TryWithResourceReducerclass now transforms every try-with-resources statement into the equivalent nested try/finally form that javac generates, enabling KeY to reason about code without requiring native support for try-with-resources syntax.Technical Details
For a simple try-with-resources:
The transformation produces:
Key features:
try (Resource r = expr)and Java 9+ styletry (existingVar)formsType of pull request
Ensuring quality
Additional information and contact(s)
Author: @weigl, with contributions from Claude Sonnet
This transformation is part of the broader effort to normalize Java constructs for formal verification in KeY. The implementation follows the exact semantics specified in JLS 14.20.3 and mirrors the bytecode-level transformation performed by javac.
Contributions within this pull request are licensed under GPLv2 (only) for inclusion in KeY.